package com.acs.player;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.acs.player.constants.PlayerConst;
import com.acs.player.entities.Music;
import com.acs.player.media.Player;
import com.acs.player.media.RetrieveData;
import com.acs.player.views.simple.TrackAdapter;


public class SimpleActivity extends Activity {
	
	private List<Music> allTracksList;
	private Menu menu;
	private int current_theme ; 
//	private SkinClass skin ; 
	private int currentTrack;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_view); 
        
        //GET ALL TRACKS
        RetrieveData retrieveData = RetrieveData.getRetrieveData(this);
        allTracksList = retrieveData.getAllTracksList();
        
        //CREATE TRACK LIST
		TrackAdapter trackAdapter = new TrackAdapter(this, R.layout.row_music, allTracksList);	
		ListView listView = (ListView) findViewById(R.id.listViewSimple);
    	listView.setAdapter(trackAdapter);
        
        //CREATE MENU
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.the_mother_of_all_views_navigator);       
        menu = new Menu();
        LinearLayout linearLayout = menu.createMenu(this);
        relativeLayout.addView(linearLayout);
        
       
        
        
    }
    
    @Override
    protected void onNewIntent(Intent intent) {
    	//Log.e("test", "test");
    	//SET THEME
    	SkinClass skin = SkinClass.getSkinClass(); 
    	 if(current_theme != skin.getCURRENT_SKIN() )
         {
         	Log.d("DebugTEST",""+ current_theme);
         	//recuperer Get current Shape
         	//Set le shape au relativeLayout
         	RelativeLayout rel = (RelativeLayout) findViewById(R.id.the_mother_of_all_views_navigator);
         	rel.setBackgroundColor(Color.BLUE);
         }
    }
    
    public void click(View view){
    	menu.click(view);
    }

    public void goToPlayerActivity(int trackIndex){	
    	Player player = Player.getPlayer();

		if(!player.getTrackListsToPlay().equals(allTracksList)){
			player.setTrackListsToPlay(allTracksList);
			player.setCurrentActivity(PlayerConst.SIMPLE_VIEW);
		}
    	
    	Intent intent = new Intent(SimpleActivity.this, PlayerActivity.class); 
    	intent.putExtra(PlayerConst.CURRENT_TRACK_INDEX_KEY, trackIndex);
    	intent.putExtra(PlayerConst.PREVIOUS_ACTIVITY_KEY, PlayerConst.SIMPLE_VIEW);
    	
    	startActivity(intent);
    }
}
